package com.redxun;

import com.redxun.core.common.app.DefaultApplication;
import com.redxun.core.common.constant.ServiceNameConstants;
import com.redxun.core.common.utils.ExceptionUtil;
import com.redxun.core.loadbalance.annotation.EnableAiFeignInterceptor;
import com.redxun.core.tool.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.io.File;

/**
 * AojuApplication.
 * @author aj
 */
@Slf4j
@EnableFeignClients
@EnableAiFeignInterceptor
@MapperScan({"com.redxun.dao"})
@SpringBootApplication(scanBasePackages = {"com.redxun","com.xxl"})
public class BootApplication {
    
    public static void main(String[] args) {
        try {
            ApplicationHome h = new ApplicationHome(BootApplication.class);
            File jarF = h.getSource();
            String startPath = jarF.getParentFile().toString();
            String location = System.getProperty("spring.config.location");
            String confPath = jarF.getParentFile().getParentFile() + File.separator + "config";
            if(StringUtils.isNotEmpty(location) ){
                confPath = location;
            }
            String userHome = jarF.getParentFile().getParentFile().toString();
            log.debug("configPath: " + confPath);
            System.setProperty("configPath", confPath);
            System.setProperty("user.home", userHome);
            DefaultApplication.run(ServiceNameConstants.AJ_BOOT, BootApplication.class, startPath, "", args);
        } catch (Exception e) {
            log.error(ExceptionUtil.getExceptionMessage(e));
        }
    }
}
